<template>
	<view class="behavior-item" @tap.stop="toMemberZone">
		<image class="face" :src="item.user.avatar"></image>
		<view class="text">
			<view class="name">{{ item.user.nickName }}</view>
			<view class="note">{{ note }}</view>
		</view>
		<template v-if="type != 'hello'">
			<view class="btn" v-if="follow == 1" @tap.stop="askCancel">相互关注</view>
			<view class="btn" v-else-if="type == 'fans' && follow == 0" @tap.stop="handelFavor">回关</view>
			<view class="btn" v-else-if="type == 'favors' && follow == 0" @tap.stop="askCancel">取消关注</view>
			<view class="btn" v-else-if="type == 'favors' && follow == -1" @tap.stop="handelFavor">关注</view>
		</template>
		<view class="btn" style="width: 90rpx;" v-else @tap="toMemberZone">查看</view>
	</view>
</template>

<script>
export default {
	props: {
		type: {
			default: 'fans',
			type: String
		},
		item: {
			default() {
				return {};
			},
			type: Object
		}
	},
	watch: {
		item: {
			handler(newValue, oldValue) {
				if (newValue.hasOwnProperty('follow')) {
					this.follow = newValue.follow;
				}
			},
			immediate: true,
			deep: true
		}
	},
	data() {
		return {
			list: [],
			follow: 1
		};
	},
	computed: {
		note: function() {
			const { user } = this.item;
			if (user.introduce) {
				return user.introduce;
			}
			if (user.label) {
				const label = JSON.parse(user.label);
				const labelList = [];
				label.map(item => {
					labelList.push(item.name);
				});
				return labelList.join('/');
			}
			if (user.province || user.city) {
				return `${user.province}  ${user.city}`;
			}
			return '对方很懒，什么都不想写';
		}
	},

	methods: {
		handelFavor() {
			this.$u.api.doHehaviorToSex(this.item.user.user_id, 10).then(res => {
				this.$emit('handle', {});
			});
		},
		askCancel() {
			uni.showActionSheet({
				itemList: ['取消关注', '再想想'],
				success: res => {
					if (res.tapIndex == 0) {
						this.handelFavor();
					}
				}
			});
		},
		toMemberZone() {
			this.visitUserZone(this.item.user.user_id, null, 10);
		}
	}
};
</script>

<style lang="scss">
.behavior-item {
	height: 150rpx;
	padding: 25rpx 30rpx;
	background: #fff;
	display: flex;
	align-items: center;
	.face {
		height: 100rpx;
		width: 100rpx;
		border-radius: 50rpx;
		flex-shrink: 0;
	}
	.text {
		margin-left: 25rpx;
		margin-right: 10rpx;
		flex: 1;
		.name {
			font-size: 30rpx;
			height: 42rpx;
		}
		.note {
			margin-top: 6rpx;
			font-size: 24rpx;
			height: 36rpx;
			color: #626670;
			@include ellipsis(1);
		}
	}
	.btn {
		height: 55rpx;
		width: 160rpx;
		flex-shrink: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: $theme-main-color;
		color: #fff;
		border-radius: 4rpx;
		font-size: 26rpx;
	}
}
</style>
